﻿
namespace XXTBaseService
{
    public class ErrorMsg
    {
        public string Type;
        /// <summary>
        /// 错误代码
        /// </summary>
        public string Code;
        /// <summary>
        /// 错误信息
        /// </summary>
        public string Message;
        /// <summary>
        /// 错误描述
        /// </summary>
        public string Description;

        public string Remark;
    }
    public class Error
    {
        public static ErrorMsg CheckError(string code) 
        {
            if (string.IsNullOrEmpty(code)) 
            {
                return null;
            }
            ErrorMsg error = null;
            if (code.Length >= 2 && (code.EndsWith("1") || code.EndsWith("2")))
            {
                error = new ErrorMsg();
                if (code.EndsWith("1"))
                {
                    error.Message = "IP鉴权不通过";
                    error.Description = "学校提供的登录iP 和 实际登录不同";
                }
                else
                {
                    error.Message = "学校ID错误";
                    error.Description = "登录的学校ID，在平台不存在";
                }
                char beginCode = code[0];
                switch (beginCode)
                {
                    case '1':
                        error.Type = "单点登录";
                        break;
                    case '2':
                        error.Type = "教师资料变更";
                        break;
                    case '3':
                        error.Type = "学生资料变更";
                        break;
                    case '4':
                        error.Type = "家长资料变更";
                        break;
                    case '5':
                        error.Type = "订购关系变更";
                        break;
                    case '6':
                        error.Type = "短信下行接口";
                        break;
                    case '7':
                        error.Type = "短信上行";
                        break;
                }

            }
            else
            {
                error = new ErrorMsg();
                switch (code)
                {
                    case "0":
                        error.Type = "所有消息";
                        error.Message = "对未定义错误的描述";
                        error.Description = "未定义错误";
                        break;
                    case "103":
                        error.Type = "单点登录";
                        error.Message = "教师不存在";
                        error.Description = "根据姓名+号码在XXT无法匹配到教师";
                        break;
                    case "104":
                        error.Type = "单点登录";
                        error.Message = "字段值无法解析";
                        error.Description = "无法解析xml";
                        break;
                    case "203":
                        error.Type = "教师资料变更";
                        error.Message = "教师不存在";
                        error.Description = "根据teacherId无法匹配到教师资料";
                        break;
                    case "204":
                        error.Type = "教师资料变更";
                        error.Message = "字段值无法解析";
                        error.Description = "Role不是4，5，6，actionCode不是1，2，3";
                        break;
                    case "303":
                        error.Type = "学生资料变更";
                        error.Message = "学生不存在";
                        error.Description = "根据studentId无法匹配到学生资料";
                        break;
                    case "304":
                        error.Type = "学生资料变更";
                        error.Message = "字段值无法解析";
                        error.Description = "grade不合法，或者 actionCode不是1，2，3";
                        break;
                    case "305":
                        error.Type = "学生资料变更";
                        error.Message = "违反业务约束";
                        error.Description = "家长还有订购关系不能删除";
                        break;
                    case "403":
                        error.Type = "家长资料变更";
                        error.Message = "学生ID不存在";
                        error.Description = "StuId在XXT平台不存在";
                        break;
                    case "404":
                        error.Type = "家长资料变更";
                        error.Message = "字段值无法解析";
                        error.Description = "Relationship不合法，或者 actionCode不是1，2，3";
                        break;
                    case "405":
                        error.Type = "家长资料变更";
                        error.Message = "扣费号码错误";
                        error.Description = "扣费号码不合法";
                        break;
                    case "406":
                        error.Type = "家长资料变更";
                        error.Message = "接收短信号码为空";
                        error.Description = "接收短信号码为空";
                        break;
                    case "407":
                        error.Type = "家长资料变更";
                        error.Message = "号码有订购关系不能删除";
                        error.Description = "号码有订购关系不能删除";
                        break;
                    case "503":
                        error.Type = "订购关系变更";
                        error.Message = "字段值无法解析";
                        error.Description = "Servicecode,charge不合法，或者 actionCode不是1，2，3";
                        break;
                    case "504":
                        error.Type = "订购关系变更";
                        error.Message = "家长ID不存在";
                        error.Description = "familyId在XXT平台不存在";
                        break;
                    case "505":
                        error.Type = "订购关系变更";
                        error.Message = "业务限制";
                        error.Description = "没有订购关系，不能取消或者转收费";
                        break;
                    case "603":
                        error.Type = "短信下行接口";
                        error.Message = "字段值无法解析";
                        error.Description = "smstype,isLong不合法";
                        break;
                    case "604":
                        error.Type = "短信下行接口";
                        error.Message = "字段不合法";
                        error.Description = "sContent,ids 超过限定长度";
                        break;
                    case "605":
                        error.Type = "短信下行接口";
                        error.Message = "其他错误";
                        error.Description = "其他错误";
                        break;
                    default:
                        error = null;
                        break;
                }
            }
            if (error != null) 
            {
                error.Code = code;
            }
            return error;
        }
    }
}
